//
//  SWTypeCell.m
//  ShiWu
//
//  Created by liujianlong on 2022/7/29.
//

#import "SWTypeCell.h"
#import "SWHistoryCell.h"
@interface SWTypeCell()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
@property (weak, nonatomic) IBOutlet UICollectionView *listView;
@property (strong, nonatomic) IBOutlet UIImageView *noDataImg;

@end
@implementation SWTypeCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.noDataImg.hidden = YES;
    [self.listView registerNib:[SWHistoryCell nib] forCellWithReuseIdentifier:[SWHistoryCell ID]];
}
- (void)setArray:(NSArray *)array
{
    _array = array;
    self.noDataImg.hidden = array.count > 0;
    [self.listView reloadData];
}
#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return  self.array.count;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    SWHistoryCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:[SWHistoryCell ID] forIndexPath:indexPath];
    cell.model = self.array[indexPath.row];
    return  cell;
}
#pragma mark - UICollectionViewDelegate
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.block) {
        self.block(self.array[indexPath.row]);
    }
}
#pragma mark - UICollectionViewDelegateFlowLayout
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat w = (SCREEN_WIDTH - 16 * 3) / 2;
    return  CGSizeMake(w, w * 8 / 7 + 50);
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return  UIEdgeInsetsMake(16, 16, 0, 16);
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 16;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    return 16;
}
@end
